package com.woniuxy.classdeans.configuration;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author weizihan
 * @Date 2020/7/20 2020/7/20
 * @Description 配置消息队列，用来推送消息--分班，通知本年级所有的班主任和学生接受到消息
 * @Since version-1.0
 */
@Configuration
public class RabbitConfig{
    //延迟队列-队列
    @Bean
    public Queue divideClassQueue(){
        Map<String,Object> map = new HashMap<String, Object>();
        //声明当前队列绑定的死信交换机
        map.put("x-dead-letter-exchange","deadDirectExchange");
        //声明当期前队列死信路由key
        map.put("x-dead-letter-routing-key","dead_key");
        //声明队列的TTL--毫秒
        map.put("x-message-ttl",10000);
        return new Queue("divideClassQueue",true,false,false,map);
    }
    //延迟交换机-交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("dDirectExchange");
    }
    //绑定交换机和消息队列
    @Bean
    public Binding bindingFanoutExchangeQueue(Queue divideClassQueue,DirectExchange directExchange){
        return BindingBuilder.bind(divideClassQueue).to(directExchange).with("stClass");
    }

    //死信队列
    @Bean
    public Queue deadQueue(){
        return new Queue("deadQueue");
    }
    //死信交换机
    @Bean
    public DirectExchange deadDirectExchange(){
        return new DirectExchange("deadDirectExchange");
    }
    //绑定死信队列
    @Bean
    public Binding bindingDeadQueueAndDeadExchange(Queue deadQueue,DirectExchange deadDirectExchange){
        return  BindingBuilder.bind(deadQueue).to(deadDirectExchange).with("dead_key");
    }

}
